﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#include "ALSoundEffects.h"

namespace UX_STL
{
namespace ALShell
{

//--------------------------- ALSoundFilter -----------------------//
/*
=================================================
	
=================================================
*/
	ALSoundFilter::ALSoundFilter(): _uID(0), _eType(al_filter::UNKNOWN)
	{}
	
/*
=================================================
	
=================================================
*/
	ALSoundFilter::~ALSoundFilter()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteFilters( 1, &_uID ) );
			_uID = 0;
		}
	}
	
/*
=================================================
	
=================================================
*/
	bool ALSoundFilter::Create(al_filter::type eType)
	{
		Destroy();

		AL_CALL_R( alGenFilters( 1, &_uID ) );
		AL_CALL_R( alFilteri( _uID, AL_FILTER_TYPE, eType ) );
		_eType = eType;

		return true;
	}
	
/*
=================================================
	
=================================================
*/
	void ALSoundFilter::Destroy()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteFilters( 1, &_uID ) );
			_uID = 0;
		}
		_eType	= al_filter::UNKNOWN;
	}


//-------------------------- ALSoundEffect ------------------------//
/*
=================================================
	
=================================================
*/
	ALSoundEffect::ALSoundEffect(): _uID(0), _eType(al_effect::UNKNOWN)
	{}
	
/*
=================================================
	
=================================================
*/
	ALSoundEffect::~ALSoundEffect()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteEffects( 1, &_uID ) );
			_uID = 0;
		}
	}
	
/*
=================================================
	
=================================================
*/
	bool ALSoundEffect::Create(al_effect::type eType)
	{
		Destroy();

		AL_CALL_R( alGenEffects( 1, &_uID ) );
		AL_CALL_R( alEffecti( _uID, AL_EFFECT_TYPE, eType ) );
		_eType = eType;

		return true;
	}
	
/*
=================================================
	
=================================================
*/
	void ALSoundEffect::Destroy()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteEffects( 1, &_uID ) );
			_uID = 0;
		}
		_eType = al_effect::UNKNOWN;
	}


	
//---------------------- ALSoundEffectSlot ------------------------//
/*
=================================================
	
=================================================
*/
	ALSoundEffectSlot::ALSoundEffectSlot(): _uID(0)
	{}
	
/*
=================================================
	
=================================================
*/
	ALSoundEffectSlot::~ALSoundEffectSlot()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteAuxiliaryEffectSlots( 1, &_uID ) );
			_uID = 0;
		}
	}
	
/*
=================================================
	
=================================================
*/
	bool ALSoundEffectSlot::Create()
	{
		Destroy();

		AL_CALL_R( alGenAuxiliaryEffectSlots( 1, &_uID ) );
		return true;
	}
	
/*
=================================================
	
=================================================
*/
	void ALSoundEffectSlot::Destroy()
	{
		if ( _uID != 0 )
		{
			AL_CALL( alDeleteAuxiliaryEffectSlots( 1, &_uID ) );
			_uID = 0;
		}
	}

//-------------------------------------------------------------------

}	// ALShell
}	// UX_STL